package cn.zhiquxing.controller;


import cn.zhiquxing.config.TestConfig;
import cn.zhiquxing.pojo.User;
import cn.zhiquxing.service.UserBatchService;
import cn.zhiquxing.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("test")
public class TestController {
    
    @Autowired
    private UserService userService;
    
    @Autowired
    private UserBatchService userBatchService;
    
    @Autowired
    private TestConfig testConfig;
//    @Value("${test}")
//    private String test;    
    @RequestMapping("ok")
    public String test() {
        System.out.println("test config: " + testConfig.getTest());
        User user = new User();
        user.setUserName("aa");
        user.setNote("aa");
        User user1 = new User();
        user1.setUserName("bb");
        user1.setNote("bb");
        List<User> users = new ArrayList<>();
        users.add(user);
        users.add(user1);
        int i = userService.insertUsers(users);
        System.out.println("多条插入：" + i);
        return "OK";
    }
    
    @RequestMapping("user")
    public void testUser() {
        User user = new User();
        user.setUserName("aa");
        user.setNote("aa");
        User user1 = new User();
        user1.setUserName("bb");
        user1.setNote("bb");
        List<User> users = new ArrayList<>();
        users.add(user);
        users.add(user1);
        int i = userBatchService.insertUsers2(users);
        System.out.println("多条插入：" + i);
    }
    
    @RequestMapping("user1")
    public void testUser1() {
        User user = new User();
        user.setUserName("CC");
        user.setNote("CC");
        userService.insertUser2(user);
    }
}
